package com.dyzx.hbb.modules.finance.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.modules.finance.entity.FinanceOrganWallet;
import com.dyzx.hbb.modules.finance.service.FinanceOrganWalletService;
import com.dyzx.hbb.modules.finance.mapper.FinanceOrganWalletMapper;
import com.dyzx.hbb.security.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

/**
* @author Administrator
* @description 针对表【finance_organ_wallet(企业钱包表)】的数据库操作Service实现
* @createDate 2025-07-15 20:10:13
*/
@Service
public class FinanceOrganWalletServiceImpl extends ServiceImpl<FinanceOrganWalletMapper, FinanceOrganWallet>
    implements FinanceOrganWalletService{

    @Override
    public FinanceOrganWallet validBlance(Long amount) {
        Long userId = SecurityContextHolder.getUserId();
        Long organId = SecurityContextHolder.getOrganId();
        MyLambdaQueryWrapper<FinanceOrganWallet> queryWrapper =new MyLambdaQueryWrapper<>();
        queryWrapper.eq(FinanceOrganWallet::getOrganId,organId);
        queryWrapper.ge(FinanceOrganWallet::getBalance,amount);
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);

    }

    @Override
    public FinanceOrganWallet getByOrganId(Long organId) {
        MyLambdaQueryWrapper<FinanceOrganWallet> queryWrapper =new MyLambdaQueryWrapper<>();
        queryWrapper.eq(FinanceOrganWallet::getOrganId,organId);
        queryWrapper.last("limit 1");
        return this.getOne(queryWrapper);
    }
}




